<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
        1. 新闻接口
          get http://ajax-api.itheima.net/api/news
          无参数
      */
      function myAxios() {
        return new Promise((resolve, reject) => {
          const xhr = new XMLHttpRequest()
          // 调用 新闻接口
          xhr.open('get', 'http://ajax-api.itheima.net/api/news')
          xhr.addEventListener('load', function () {
            // console.log('load:', xhr.response)
            // 通过 resolve 将成功的结果传递给then
            resolve(xhr.response)
          })
          xhr.send()
        })
      }

      myAxios().then(res => {
        // console.log('then-res:', res)
        const data = JSON.parse(res)
        console.log('data:', data)
      })
    </script>
  </body>
</html>
